﻿<!DOCTYPE html>
<!--基础管理类隐患排查库-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
</head>

<body>
    <div id="app" v-cloak class="popupW100">

        <el-form label-position="right" ref="form" :inline="true" :model="formInline" class="demo-form-inline" style="margin-bottom: 15px;">
            <el-row>
                <el-col class="head-tool">
                    <div class="new_title fl">
                        <strong><img src="/static/images/icon1.png" />基础管理类隐患排查库列表</strong>
                    </div>
                    <span>
                        <btn :text="col.btnSelect" imgsrc="/static/images/search.png" linetype="3" @click="onSubmit">
                        </btn>
                        <btn :text="col.btnAdd" linetype="3" @click="UserInput('tj')"></btn>
                        <btn-template-download tempname="yh/基础管理类隐患排查库.xlsx"></btn-template-download>
                        <btn-uploadfile-list url="/API/YH_BasisInformation/Import" linetype="3"></btn-uploadfile-list>

                        <btn-export-list url="/API/YH_BasisInformation/Export" :forminline="this.formInline" linetype="3"></btn-export-list>
                        <btn :text="col.btnDelete" linetype="4" @click="onDelete"></btn>
                    </span>
                </el-col>
            </el-row>
            <el-row>
                <!--工厂组件-->
                <list-factorys v-model="formInline.model.CreateFactory" @change="factoryChange"></list-factorys>
                <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input v-model="formInline.model.InvestigationProject"
                                      :placeholder="RisksManagement.ContentsAndStandards.InvestigationItems" size="mini">
                                <template slot="prepend">
                                    {{RisksManagement.ContentsAndStandards.InvestigationItems+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input v-model="formInline.model.InvestigationContents"
                                      :placeholder="RisksManagement.ContentsAndStandards.InvestigationContents" size="mini">
                                <template slot="prepend">
                                    {{RisksManagement.ContentsAndStandards.InvestigationContents+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
        </el-form>
        <el-col :span="7">
            <div class="tree_lay">
                <h4 class="title clearfix"><strong>类别</strong></h4>
                <el-tree :data="TreeData" :props="defaultProps" show-checkbox node-key="id" ref="tree" highlight-current @node-click="handleNodeClick" default-expand-all="true">
                    <span slot-scope="scope">
                        <span>
                            <i :class="scope.data.icon"></i>
                            <template>
                                <span v-if="scope.data.icon == 'tree-open'"
                                      style="color:#12489e">{{ scope.node.label }}</span>
                                <span v-else-if="scope.data.icon == 'tree-close'"
                                      style="color: #12489e">{{ scope.node.label }}</span>
                                <span v-else>{{ scope.node.label }}</span>
                            </template>
                        </span>
                </el-tree>
            </div>
        </el-col>
        <el-col :span="17">
            <el-table stripe ref="table" :data="ListItem.tableData" :height="ListItem.tableHeight" border
                      @selection-change="handleSelectionChange" row-style="height:10px" style="width: 100%">
                <!--:span-method="objectSpanMethod"-->
                <el-table-column type="selection" align="center" width="55">
                </el-table-column>
                <el-table-column type="index" :label="RisksManagement.ContentsAndStandards.id" :index="indexMethod"
                                 width="50" show-overflow-tooltip="true" align="center"></el-table-column>
                <el-table-column prop="Tree" v-if='false' align="center"
                                 :label="RisksManagement.ContentsAndStandards.Tree" show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="investigationProject" show-overflow-tooltip="true" align="center"
                                 :label="RisksManagement.ContentsAndStandards.InvestigationItems">
                </el-table-column>
                <el-table-column prop="investigationContents" show-overflow-tooltip="true" align="center"
                                 :label="RisksManagement.ContentsAndStandards.InvestigationContents">
                </el-table-column>
                <el-table-column prop="createUserText" show-overflow-tooltip="true"
                                 :label="RisksManagement.ContentsAndStandards.Operator" width="90">
                </el-table-column>
                <el-table-column prop="createTime" show-overflow-tooltip="true" align="center"
                                 :label="RisksManagement.ContentsAndStandards.AddTime" width="170">
                </el-table-column>
                <el-table-column width="53" prop="update" :label="col.btnUpdate" fixed="right">
                    <template slot-scope="scope">
                        <button type="button" class="elst-bt-xg" @click=UserInput('xg',scope.row.id)>
                            <i class="el-icon-edit"></i>
                        </button>
                    </template>
                </el-table-column>
            </el-table>
            <el-row type="flex" justify="end">
                <el-pagination ref="page" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                               :current-page="ListItem.currentPage" :page-sizes="ListItem.pagesizes" :page-size="ListItem.pagesize"
                               :layout="ListItem.layout" :total="ListItem.total">
                </el-pagination>
            </el-row>
        </el-col>
        <el-dialog title="排查内容和排查标准管理" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%"
                   height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">

        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (!v.pid) v.pid = guidEmpty;
                if (v.pid == pid) {
                    var obj = {};
                    obj.id = v.id + '';
                    obj.label = v.name + '';
                    obj.icon = 'tree-item';
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                        obj.icon = 'tree-open';
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }

        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    //页面内左树
                    TreeData: [],
                    mydata: [],
                    defaultProps: {
                        children: 'children',
                        label: 'label'
                    },
                    //页面内数据初始化
                    ListItem: ListItem,
                    TreeStyle: {
                        border: "1px solid #EBEEF5",
                        marginRight: "10px ",
                        height: "auto"
                    },
                    formInline: {
                        model: {
                            InvestigationContents: '',
                            InvestigationProject: '',
                            Tree: '',
                            CreateFactory: null,
                            baseTypes: []
                        },
                        offset: 0,
                        limit: 10
                    }
                }
            },
            created: function () {
                var currApp = this;
                window.onresize = function () {
                    currApp.ListItem.tableHeight = window.innerHeight -
                        currApp.$refs.table.$el.offsetTop - 60;
                    if (currApp.ListItem.tableHeight < 112) {
                        currApp.ListItem.tableHeight = 112;
                    }
                    //控制tree高度
                    currApp.TreeStyle.height = currApp.ListItem.tableHeight + "px";
                }
            },
            mounted: function () {

                //列表高度自适应
                tablehigh(this);
                this.TreeData = fn(this.mydata, "0");
                //初始化tree高度
                this.$nextTick(function () {
                    this.TreeStyle.height = window.innerHeight -
                        this.$refs.table.$el.offsetTop - 60 + "px";
                })

            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //表格序号连续化
                indexMethod: function (index) { return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1; },
                getDicValue: function (row, column, cellValue, index) {
                    return getTreeValue(this.mydata, cellValue)
                },
                handleNodeClick: function (data) {
                    if (!data.children) {

                        this.$refs.tree.setCheckedKeys([]);
                        this.$refs.tree.setCheckedKeys([data.id]);
                    } else {
                        this.$refs.tree.setCheckedKeys([]);
                        this.$refs.tree.setCheckedKeys([data.id]);
                        if (data.icon == "tree-open") {
                            data.icon = "tree-close"
                        } else (
                            data.icon = "tree-open"
                        )
                    }
                    this.formInline.model.baseTypes = this.$refs.tree.getCheckedKeys()
                    onSubmit(this);
                },
                closeDialog: function () { closeDialog(this); },
                //删除方法
                onDelete: function () { onDelete(this, '/api/YH_BasisInformation/DeleteMuti'); },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //Dialog展示
                UserInput: function (val, id) { DialogShow(this, val, "ContentsAndStandardsInput.html", id); },
                //获取分页数据
                GetPageData: function (currentIndex) {
                        //注意：后台约束空值为null  但是Tree id =null时有bug体现在setCheckedKeys 所以只能在扁平化上处理为guidempty，在传给后台前设置为空数组
                    if (this.formInline.model.baseTypes.length == 1 && this.formInline.model.baseTypes[0] == guidEmpty)
                        this.formInline.model.baseTypes = []
                    GetPageData(this, currentIndex, '/api/YH_BasisInformation/GetList')
                },
                //查询方法
                onSubmit: function () { onSubmit(this); },
                //pagesize改变 触发方法
                handleSizeChange: function (val) { handleSizeChange(this, val); },
                //跳页触发方法
                handleCurrentChange: function (val) { handleCurrentChange(this, val); },
                factoryChange: function () {
                    this.TreeData = this.GetAreaTreeData(this.formInline.model.CreateFactory);
                    this.GetPageData(1);
                },
                GetAreaTreeData: function (factoryId) {
                    var mythis = this;
                    var typeData;
                    myAjax("get", mythis, '/api/yh/BasisType/' + factoryId, null, function (response) {
                        var dataSource = response.data;
                        var data = MenuHelper(dataSource, guidEmpty);
                        data.unshift({ id: guidEmpty, label: '全部', Id: guidEmpty })//初始化无父级的选项
                        typeData = data;
                    }, false);
                    return typeData;
                }
            }
        });

    </script>
</body>

</html>